/**
 * Created by wangxiaoqiang on 2017/8/23.
 */
// const rootPath = "https://cake.sanploy.cn";//请求数据的根路径
const rootPath = "http://localhost:8081";//请求数据的根路径

let nv = new NiceValidate([
    {dom:document.querySelector("#username")},
    {dom:document.querySelector("#password")}
]);

/**
 * login
 */

$(".btn_login").click(()=> {
    loginImpl()
});

function loginImpl() {
    if(nv.niceValidate()){
        $.post(rootPath+"/login",nv.niceValidate(),(res)=> {
            if(res.code === '200'){
                localStorage.setItem("username",res.username);
                localStorage.setItem("authoritys",res.authoritys);
                location.href = "./index/index.html"
            }else {
                alert(res.message+"：用户名或密码错误")
            }
        })
    }
}

document.querySelector("#password").onkeydown=function(event){
    let e = event || window.event || arguments.callee.caller.arguments[0];
    if(e && e.keyCode===13){ // enter 键
        loginImpl()
    }
};